<template>
  <!-- 修改登陆密码 -->
  <a href="/meData.html"><span class="logonImg"><img src="img/left.jpg"></span></a>
    <div class="dataPasswordMid">
      <div><span>当前密码</span><input class="txt" type="password" placeholder="请输入当前密码"></div>
      <div><span>新密码</span><input class="pwd" style="margin-left: 9%" type="password" placeholder="请输入新密码" ></div>
      <div><span>确认密码</span><input class="pwd" type="password" placeholder="请再输入一次新密码"  ></div>
      <div class="btn"  @touchstart="upDataPass()" >保存</div>
  </div>
</template>

<script>
export default {
  methods:{
      upDataPass:function(){
      var $pwd = $(".pwd");
      var $txt = $(".txt");
      var $name=localStorage.getItem("username")
      if ($txt.val().trim()=="") {
        alert("当前密码不能为空");
        return;
      }else if ($txt.val().length<6) {
        alert("当前密码长度不少于6个字符");
        return;
      } 
      else if ($pwd.eq(0).val()=="" && $pwd.eq(1).val()=="") {
        alert("密码不能为空");
        return;
      }else if ($pwd.eq(0).val().length<6) {
        alert("密码长度不能少于6个字符");
        return;
      }else if ($pwd.eq(0).val()!=$pwd.eq(1).val()) {
        alert("密码不一致");
        return;
      }else{
            $.ajax({
          type:"GET",
          url: "http://localhost/login/login.php",
          data:{type:"upDataPass",name:$name,pwd:$txt.val(),npwd:$pwd.eq(0).val()},
          dataType:"jsonp",
          jsonp:"cb",
          success:function(data){
            if (data.error==0) {
              alert('修改成功！');
              location.href="/login.html";
            }else{
              alert("当前密码错误");
            }
          }
        })
      }
      }
  }
}
</script>
<style scoped>
   .logonImg{
    display: inline-block;
    position: fixed;
    top: 1.5%;
    width: 5%;
    left: 2%;
    z-index:1888;
  }
   .logonImg img{
    width:100%;
  }
  
    .dataPasswordMid div{
    width: 85%;
    margin: 5% auto;
    margin-bottom: 0;
    height: 0.4rem;
    line-height:0.4rem;
    border:1px solid #dbdbdb;
    border-radius: 5px;
    background-color: white; 
  }
    .dataPasswordMid div input{
      width: 70%;
      outline:none;
      border:none;
      margin-left:5%;
  }
  .dataPasswordMid div span{
      width: 70%;
      outline:none;
      border:none;
      margin-left:5%;
  }
  .dataPasswordMid .btn{
    width: 80%;
    margin-top: 15%;
    background-color: #f29004;
    text-align: center;
    color: white;
    font-size: 12px;
  }
</style>

